Skip to content

feat(language)!: relation rows index an entry and a sum - #7

Draft
FBumann wants to merge 12 commits into
feat/dimension-aliasfrom
compare/confine
Draft

FBumann wants to merge 12 commits into
feat/dimension-aliasfrom
compare/confine

Conversation

@FBumann

@FBumann FBumann commented Nov 17, 2026 •

Copy link
Copy Markdown

Prompt: Can you update my fork and do stacked PRs there comparing that? bsed on the alias or maps PR?

Note

The following content was generated by AI.

What this changes

Confine (energy-models#1016) on the alias PR, plus one thing: sum(…, over=<relation>) sums over the relation's key instead of refusing.

examples/sparse.yaml, before (feat/dimension-alias):

relations:
  connection: { dims: [unit, port], missing: absent }
  active: { dims: [unit, period], missing: absent }
mappings:
  connection:
    bus: { dim: bus }
parameters:
  efficiency: { dims: [unit, port, period], where: connection, missing: 1 }
variables:
  output: { dims: [unit, period], where: active }
  flow: { dims: [unit, port, period], where: connection }
constraints:
  port_limit: { dims: [unit, port, period], expression: flow <= capacity }
  ramp_up: { dims: [unit, period], expression: "output - shift(output, along=period, offset=1) <= ramp" }
  balance: { dims: [bus, period], expression: "sum(efficiency * flow, over=[unit, port], by=connection[bus]) >= load" }

After (this PR, loads with to_spec):

relations:
  connection: { dims: [unit, port], missing: absent }
  active: { dims: [unit, period], missing: absent }
mappings:
  connection:
    bus: { dim: bus }
parameters:
  efficiency: { dims: [unit, port, period], in: [connection], missing: 1 }
variables:
  output: { dims: [unit, period], in: [active] }
  flow: { dims: [unit, port, period], in: [connection] }
constraints:
  port_limit: { dims: [unit, port, period], expression: flow <= capacity }
  ramp_up: { dims: [unit, period], expression: "output - shift(output, along=period, offset=1) <= ramp" }
  balance: { dims: [bus, period], expression: "sum(efficiency * flow, over=connection, by=connection[bus]) >= load" }

TIMES (examples/times/):

act:     { dims: [region, vintage, period, process, timeslice], in: [prc_ts, rtp_vintyr] }
ire_flo: { dims: [from_region, from_commodity, region, commodity, process], in: [top_ire] }

(before: the same dims: with where: rtp_vintyr AND prc_ts and where: top_ire)

Why

Draft, for comparison, not for merge. The other design: #8 (Multi-dims).

  • An entry lists its dimensions in dims: and confines itself with in:.
  • over= a relation stands for the relation's key columns, not its mappings. Beside by= the same relation, the key stays as column names.
  • along= and dims: still refuse a relation, with its dimensions as the rewrite.
  • Constraints keep feat(language)!: relation rows may index an entry energy-models/mathspec#1016's behaviour: rows follow their operands, no in:.
Method, gate output, alternatives

Method

  • Fork main was not updated: the push of upstream main (fast-forward, 37 commits ahead) was refused by this session's permission check. Upstream feat/dimension-alias is on the fork as the base: first 96c1002, then fast-forwarded (no force) to 06e52956.
  • Branch = upstream feat/maps-in (c8ee83d) + merge of feat/dimension-alias at 96c1002. Conflicts in examples/times/trade.yaml and its gallery page: took upstream's process column, kept in: [top_ire], rewrote the prose, regenerated the page.
  • Rename merge 7bdb46c7: merged feat/dimension-alias at 06e52956 (upstream's maps: → mappings:). 12 conflicts in 11 files, each the rename against a line this branch changed. Each kept this branch's meaning. The lines this branch adds now say mappings:, MappingSpec, Spec.mappings, _mapping_targets, subject[mapping] and "mapping". Generated files regenerated. Gate after the merge: lint pass; test 4304 passed, 1 skipped; docs-build no issues; render-tex 62 specs; compile-tex blocked as below.
  • _expression_resolver._relations_expanded replaces a relation in over= with its key.
  • Bug hit on the way: the first draft expanded to every dimension a column is over, the mappings' too, so over=connection, by=connection[bus] named bus twice. Reproduced in test_a_sum_over_a_relation_with_a_map_sums_over_its_key_alone (fails on the first draft, passes now).
  • The over case left test_a_relation_named_where_a_dimension_belongs_is_refused; its coverage moved to test_a_sum_over_a_relation_is_a_sum_over_its_dims (plain, list, beside by=) and …_names_that_dim_twice.
  • Docs: relations page and the name-kind table of the expressions page.

Gate (pixi 0.84.2, the default environment, at 7bdb46c7)

  • pixi run lint: all hooks pass.
  • pixi run test: 4304 passed, 1 skipped.
  • pixi run docs-build: no issues.
  • pixi run render-tex: 62 specs rendered.
  • pixi run compile-tex: not run to completion. tectonic cannot download its bundle from relay.fullyjustified.net here.

Not done

🤖 Generated with Claude Code

https://claude.ai/code/session_018B3nA1Y7i5TWDbh9SKx86i

claude and others added 10 commits November 16, 2026 16:25
energy-models#980's `in:` on top of energy-models#1015's maps. A parameter or a variable lists under
`in:` the relations whose rows it exists on; a tool refuses a data row of a
parameter outside them. A relation's bare name in the `where:` of a
parameter or a variable is refused, with `in:` as the rewrite.

Co-Authored-By: Fabian Hofmann <fab.hof@gmx.de>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1xxh6NMJN6mrYY34Q
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1xxh6NMJN6mrYY34Q
An entry over a dimension twice, as TIMES' IRE_FLO: the alias's docs example
lists the links under in:, and a test states IRE_FLO in this spelling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1xxh6NMJN6mrYY34Q
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1xxh6NMJN6mrYY34Q
The TIMES examples in this PR's spelling: act lists prc_ts and
rtp_vintyr under in:, and ire_flo, trade_cost and export list top_ire,
in place of the where: that A refuses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1xxh6NMJN6mrYY34Q
sparse.yaml in this PR's spelling: efficiency, flow and output list their
relation under in:, so a stray data row is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1xxh6NMJN6mrYY34Q
…pare/confine

# Conflicts:
#	docs/examples/times/trade.md
#	examples/times/trade.yaml
`sum(x, over=connection)` was refused with the relation's dims as the
rewrite. The load now writes that rewrite: a relation in `over=` stands for
the columns of its key, and for none of its maps. `along=` and `dims:` keep
refusing a relation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1Y7i5TWDbh9SKx86i
@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1Y7i5TWDbh9SKx86i
The base renames `maps:` to `mappings:`. The lines this branch adds say
the same: `mappings:`, `MappingSpec`, `Spec.mappings`, `subject[mapping]`
and "mapping" in messages, docstrings, tests and the reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1Y7i5TWDbh9SKx86i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants